package com.xz.group12306.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.xz.group12306.business.service.ManagerService;
import com.xz.group12306.business.service.impl.ManagerServiceImpl;
import com.xz.group12306.domain.User;

/**
 * 管理员更新用户信息Servlet1
 */
@WebServlet("/ManageUpdateServlet")
public class ManageUpdateServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * 构造方法
	 */
	public ManageUpdateServlet() {
		super();
	}

	/**
	 * doGet()方法
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * doPost()方法
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		/**
		 * 获取表单提交的数据，封装成user对象
		 * 获取UserService类的实例(对象)，执行findUserLists(user对象)方法，获取用户数据
		 * 通过setAttribute()将对象传给指定的jsp页面
         * 重定向到用户信息更新jsp页面，并传入返回的数据
		 */
		
		
		ManagerService managerService=new ManagerServiceImpl();
		String id = request.getParameter("id");
		String userName = request.getParameter("username");
		String cert = request.getParameter("cert");
        
		Integer userId = Integer.parseInt(id);
		
		//System.out.println(userId);
		User user = new User();
		user.setId(userId);
		user.setUsername(userName);
		user.setCert(cert);

		User userNew = managerService.findUserService(user);
		System.out.println(userNew.getUsername());
		System.out.println(userNew.getCert());
		
		HttpSession session = request.getSession();
		session.setAttribute("user", userNew);

		response.sendRedirect("admin/ManageUpdate.jsp");
	}

}
